#ifndef X2D_H
#define X2D_H

#include "common.h"

// Placed symbol
template <AllegroVersion version>
struct x2D
{
    uint16_t t;
    uint8_t layer;
    uint8_t un0;
    
    uint32_t k;
    uint32_t un1; // Points to x2B or x2D
    
    // Points to x2B?
    
    // Points to instance (x07) or null
    uint32_t inst_ref_16x;
    
    uint16_t un2;
    uint16_t un3;
    
    
    // Bit 0 = part is rotated to non-90 deg angle?
    uint32_t bitmask1;
    
    uint32_t rotation;
    int32_t coords[2];
    
    // Points to instance (x07) or null
    
    uint32_t ptr1; // x14
    
    uint32_t first_pad_ptr; // x32
    
    uint32_t ptr3; // x03 or x30
    
    // ptr4[1] = bounding box?
    uint32_t ptr4[3]; // x24 or x28 or x0E
    
    // x26 instance indicating group membership
    uint32_t group_assignment_ptr;
    
    uint32_t TAIL;
    operator x2D<A_174>() const;
    static constexpr AllegroVersion versions[1] = {A_172};
};

#if __cplusplus >= 202002L
template <AllegroVersion version> requires(version >= A_172)
struct x2D<version>
{
    uint16_t t;
    uint8_t layer;
    uint8_t un0;

    uint32_t k;
    uint32_t un1; // Points to x2B or x2D

    // Points to x2B?
    uint32_t un4;

    // Points to instance (x07) or null

    uint16_t un2;
    uint16_t un3;

    uint32_t un5;

    // Bit 0 = part is rotated to non-90 deg angle?
    uint32_t bitmask1;

    uint32_t rotation;
    int32_t coords[2];

    // Points to instance (x07) or null
    uint32_t inst_ref;

    uint32_t ptr1; // x14

    uint32_t first_pad_ptr; // x32

    uint32_t ptr3; // x03 or x30

    // ptr4[1] = bounding box?
    uint32_t ptr4[3]; // x24 or x28 or x0E

    // x26 instance indicating group membership
    uint32_t group_assignment_ptr;

    uint32_t TAIL;
    operator x2D<A_174>() const;
    static constexpr AllegroVersion versions[1] = {A_172};
};
#else
template <> struct x2D<A_172>
{
    uint16_t t;
    uint8_t layer;
    uint8_t un0;

    uint32_t k;
    uint32_t un1; // Points to x2B or x2D

    // Points to x2B?
    uint32_t un4;

    // Points to instance (x07) or null

    uint16_t un2;
    uint16_t un3;

    uint32_t un5;

    // Bit 0 = part is rotated to non-90 deg angle?
    uint32_t bitmask1;

    uint32_t rotation;
    int32_t coords[2];

    // Points to instance (x07) or null
    uint32_t inst_ref;

    uint32_t ptr1; // x14

    uint32_t first_pad_ptr; // x32

    uint32_t ptr3; // x03 or x30

    // ptr4[1] = bounding box?
    uint32_t ptr4[3]; // x24 or x28 or x0E

    // x26 instance indicating group membership
    uint32_t group_assignment_ptr;

    uint32_t TAIL;
    operator x2D<A_174>() const;
    static constexpr AllegroVersion versions[1] = {A_172};
};
template <> struct x2D<A_174> : x2D<A_172> {};
#endif

#endif // X2D_H
